// Fig. 11.20: Complex.cpp
// Complex class member-function definitions.

#include "Complex.h" // Complex class definition

// Constructor
Complex::Complex( double realPart, double imaginaryPart ) 
   : real( realPart ),
   imaginary( imaginaryPart ) 
{ 
   // empty body
} // end Complex constructor

// addition operator
Complex Complex::operator+( const Complex &operand2 ) const
{
   return Complex( real + operand2.real, 
      imaginary + operand2.imaginary );
} // end function operator+

// subtraction operator
Complex Complex::operator-( const Complex &operand2 ) const
{
   return Complex( real - operand2.real, 
      imaginary - operand2.imaginary );
} // end function operator-

Complex Complex::operator*( const Complex &operand2 ) const
{
   return Complex( real * operand2.real - imaginary * operand2.imaginary,
      real *operand2.imaginary + imaginary * operand2.real);
}

// display a Complex object in the form: (a, b)
ostream & operator<< (ostream & out, const Complex & rhs)
{ 
   out << '(' << rhs.real << ", " << rhs.imaginary << ')';
   return out;
} // end function print

istream & operator>> (istream & in, Complex & rhs)
{ 
   in.ignore ();
   in >> rhs.real;
   in.ignore ();
   in >> rhs.imaginary;
   return in;
}

bool Complex::operator== (const Complex & rhs) const
{
   return (imaginary == rhs.imaginary) && (real == rhs.real);
}

bool Complex::operator!= (const Complex & rhs) const
{
   return !(*this == rhs);
}
